package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// PublishSchedule 投放计划表
type PublishSchedule struct {
	ID                string  `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	Name              string  `json:"name" gorm:"column:name;type:string;size:50;not null;default:'';comment:计划名称"`
	Position          int8    `json:"position" gorm:"column:position;type:tinyint(1);not null;default:1;comment:所属位置,1前屏,2后屏"`
	PublishType       int8    `json:"publish_type" gorm:"column:publish_type;type:tinyint(1);not null;default:1;comment:投放类型,1刊例2精准3刊例多素材"`
	PublishCount      int64   `json:"publish_count" gorm:"column:publish_count;type:int;size:64;not null;default:0;comment:投放次数"`
	DeviceCount       int64   `json:"device_count" gorm:"column:device_count;type:int;size:64;not null;default:0;comment:设备数"`
	PublishUsedCount  int64   `json:"publish_used_count" gorm:"column:publish_used_count;type:int;size:64;not null;default:0;comment:已使用投放次数"`
	StartTime         int64   `json:"start_time" gorm:"index:idx_startTime;column:start_time;type:int;size:64;not null;default:0;comment:开始时间"`
	EndTime           int64   `json:"end_time" gorm:"index:idx_endTime;column:end_time;type:int;size:64;not null;default:0;comment:结束时间"`
	Duration          int64   `json:"duration" gorm:"column:duration;type:int;size:64;not null;default:0;comment:计划总时长[s]"`
	Details           string  `json:"details" gorm:"column:details;type:text;not null;comment:素材详情页"`
	DetailsShow       int8    `json:"details_show" gorm:"column:details_show;type:tinyint(1);not null;default:0;comment:素材详情页开关,0关1开,默认关闭"`
	Status            int8    `json:"status" gorm:"column:status;type:tinyint(1);not null;default:1;comment:状态:1未提审,2审核中,3投放中,4待开始,5审核失败,6已结束"`
	DistrictID        string  `json:"district_id" gorm:"column:district_id;type:text;not null;comment:县区id"`
	LocationID        string  `json:"location_id" gorm:"column:location_id;type:text;not null;comment:商圈id"`
	Gender            string  `json:"gender" gorm:"column:gender;type:varchar(20);not null;default:'';comment:投放性别,1男,2女,多选"`
	Age               string  `json:"age" gorm:"column:age;type:varchar(20);not null;default:'';comment:投放年龄,1=7~12,2=13~19,3=20~29,4=30~39,5=40~49,6=50+,多选"`
	Tag               string  `json:"tag" gorm:"column:tag;type:varchar(100);not null;default:'';comment:投放标签,多选"`
	MerchantID        string  `json:"merchant_id" gorm:"column:merchant_id;primaryKey;type:varchar(30);not null;default:'';comment:商户id"`
	MerchantName      string  `json:"merchant_name" gorm:"column:merchant_name;primaryKey;type:varchar(50);not null;default:'';comment:商户名称"`
	CreateUser        string  `json:"create_user" gorm:"column:create_user;primaryKey;type:varchar(30);not null;default:'';comment:用户id"`
	CreateUserName    string  `json:"create_username" gorm:"column:create_username;primaryKey;type:varchar(50);not null;default:'';comment:用户名称"`
	CreatedAt         int64   `json:"created_at" gorm:"column:created_at;autoCreateTime;type:int;size:64;not null;default:0;index:created_at;comment:创建时间"`
	DeletedAt         int64   `json:"deleted_at" gorm:"column:deleted_at;type:int;size:64;not null;default:0;comment:删除时间"`
	OrderID           string  `json:"order_id" gorm:"column:order_id;type:varchar(128);comment:订单ID"`
	PayAmount         float32 `json:"pay_amount" gorm:"column:pay_amount;type:decimal(10,2);default:0.00;comment:支付金额计算优惠"`
	PaidAmount        float32 `json:"paid_amount" gorm:"column:paid_amount;type:decimal(10,2);default:0.00;comment:已支付金额"`
	DiscountAmount    float32 `json:"discount_amount" gorm:"column:discount_amount;type:decimal(10,2);default:0.00;comment:下单时优惠一共减免数"`
	CustomName        string  `json:"custom_name" gorm:"column:custom_name;type:varchar(200);comment:姓名"`
	PhoneNumber       string  `json:"phone_number" gorm:"column:phone_number;type:varchar(200);comment:电话"`
	OutTradeNo        string  `json:"out_trade_no" gorm:"column:out_trade_no;type:varchar(200);comment:交易号"`
	SupportActivityID string  `json:"support_activity_id" gorm:"column:support_activity_id;type:varchar(200);comment:应援活动id"`
}

// TableName 表名
func (PublishSchedule) TableName() string {
	return "publish_schedule"
}

// BeforeCreate 自增id
func (l *PublishSchedule) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID == "" {
		// id为空时，自动添加id
		uuid, err := helper.UUID{}.String()
		if err != nil {
			return err
		}
		l.ID = uuid
	}
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &PublishSchedule{})
}
